package bairui.international.console.web.controller.delicate.category.product;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.lianjing.sh.model.uml.model.status.State_UpDown;
import com.lianjing.sh.project.commons.util.Util_FileDeal;
import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.sh_lianjing.util.Util_BeanCopyByDeclaredProperties;

import bairui.international.model.domain.jpa.TB_Product;
import bairui.international.model.domain.jpa.TB_ProductRollImage;
import bairui.international.service.Service_ProductRollImage;

/**
 *
 * 产品滚动图片添加
 *
 * @generated
 * 
 * @see STest_C_Delicate_Category_ProductRollUpload_FileUpload 测试
 *
 */
@Controller
public class C_Delicate_Category_ProductRollUpload_FileUpload
 extends SC_Delicate_Category_ProductRollUpload_FileUpload 
{
	
	@Autowired private Service_ProductRollImage service_ProductRollImage;
	
	/**
	 * 上传文件
	 */
	@Action(FileUpload.class)
	@PostMapping(FileUpload.RequestMappingValue)
	public @FomatOutput @ResponseBody Object fileUpload(
		@Valid Input_FileUpload_Input_Upload.Model input, 
		@PathVariable(name=FileUpload.PathVariableName.CategoryId) long categoryId, 
		@PathVariable(name=FileUpload.PathVariableName.Id) long id
	) throws Exception {
		for(MultipartFile item : input.getFileUrlFile()){
			TB_ProductRollImage bean = new TB_ProductRollImage();
			// 上传文件相关
			Util_FileDeal
				.saveFile(item, pathConfig.getPosition_Image_ProductRollImage())
				.resultTo(bean);
			// 保存数据
			TB_ProductRollImage save = Util_BeanCopyByDeclaredProperties.copyProperties(input, bean);
				save.setState(State_UpDown.Draft);
				save.setProduct(new TB_Product(id));
			service_ProductRollImage.save(save);
		}
		return null;
	}
	

}
